package nagel_schreckenberg;

import java.util.ArrayList;

/*
 * Decprecated
 */
public class SingleLane {
	
	private ArrayList<Vehicle> cells;
	private int length;
	private SingleLane end;
	private CarFactory fac;
	private Intersection source;
	private Intersection target;
	
	public SingleLane(int length){
		this.cells = new ArrayList<Vehicle>();
		this.length = length;
	}
/*	
	public SingleLane connectIntersectionTarget(Intersection i){
		this.target = i;
		return this;
	}
	
	public SingleLane connectIntersectionSource(Intersection i){
		this.source = i;
		return this;
	}
	
	public SingleLane connectFactory(CarFactory f){
		this.fac = f;
		return this;
	}
*/	
	public void connect(SingleLane l){
		end = l;
	}
	
	public void addVehicle(Vehicle v){
		cells.add(v);
	}
	
	public void removeVehicle(int position){
		cells.remove(position);
	}
	
	public int distToNextVehicle(int nr){
		int distance = 0;
		if(nr!=0){
			distance = cells.get(nr-1).getPosition()-cells.get(nr).getPosition();
		}
		else{
			ArrayList<Vehicle> endlane = end.getLaneOccupation();
			distance = (length-cells.get(nr).getPosition()) + endlane.get(endlane.size()-1).getPosition();
		}
		return distance;
	}
	
	public ArrayList<Vehicle> getLaneOccupation(){
		return cells;
	}
	
	public SingleLane getNextLane(){
		return end;
	}
	
	public int getLength(){
		return length;
	}
	
	public void lanePrint(){
		System.out.print("Lane " +this.toString()+ " ");
		for(int i = 0; i < cells.size(); i++){
			System.out.print(cells.get(i) + " ");
		}
		System.out.println();
	}
}
